package com.jhgsys.internal.sypq.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.sypq.entity.TaskOars;
import com.jhgsys.internal.sypq.service.ITaskOarsService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 * 任务所城桨模 Controller
 *
 * @author ganjun
 * @date 2024-11-18 10:34:59
 */
@Slf4j
@Validated
@Controller
public class TaskOarsController extends BaseController {

    @Autowired
    private ITaskOarsService taskOarsService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "taskOars")
    @RequiresPermissions("taskOars:view")
    public String taskOarsIndex(){
        return jumpPage("sypq/taskOars/taskOarsList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "taskOars/add")
    @RequiresPermissions("taskOars:add")
    public String taskOarsAdd(){
        return jumpPage("sypq/taskOars/taskOarsEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "taskOars/update/{id}")
    @RequiresPermissions("taskOars:edit")
    public String taskOarsUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("taskOars", taskOarsService.findTaskOarsById(id));
        return jumpPage("sypq/taskOars/taskOarsEdit");
    }

    /**
     * 查询（所有）
     * @author ganjun
     * @date 2024-11-18 10:34:59
     */
    @GetMapping("taskOars")
    @ResponseBody
    @RequiresPermissions("taskOars:view")
    public FebsResponse getAllTaskOarss(TaskOars taskOars) {
        try {
            return success(taskOarsService.findTaskOarsList(taskOars));
        }catch (Exception ex){
            return failure(ex);
        }

    }

    /**
     * 查询（分页）
     * @author ganjun
     * @date 2024-11-18 10:34:59
     */
    @GetMapping("taskOars/list")
    @ResponseBody
    @RequiresPermissions("taskOars:view")
    public FebsResponse taskOarsList(QueryRequest request, TaskOars taskOars) {
        try {
            Map<String, Object> dataTable = getDataTable(this.taskOarsService.findTaskOarsPage(request, taskOars));
            return success(dataTable);
        }catch (Exception ex){
            return failure(ex);
        }
    }

    /**
     * 新增 TaskOars
     * @author ganjun
     * @date 2024-11-18 10:34:59
     */
    @Log("新增TaskOars")
    @PostMapping("taskOars")
    @ResponseBody
    @RequiresPermissions("taskOars:add")
    public FebsResponse addTaskOars(@Valid TaskOars taskOars) throws FebsException {
        try {
            this.taskOarsService.createTaskOars(taskOars);
            return success();
        } catch (Exception ex) {
            return failure(ex,"新增失败");
        }
    }

    /**
     * 逻辑删除 TaskOars
     * @author ganjun
     * @date 2024-11-18 10:34:59
     */
    @Log("逻辑删除TaskOars")
    @GetMapping("taskOars/delete/{id}")
    @ResponseBody
    @RequiresPermissions("taskOars:delete")
    public FebsResponse deleteTaskOars(@PathVariable("id") String taskOarsIds) throws FebsException {
        try {
            TaskOars taskOars = new TaskOars();
            taskOars.setDeletedBy(getCurrentUser().getUserName());
            taskOars.setDeletedTime(new Date());
            taskOars.setDeletedFlg(FebsConstant.INVALID);
            this.taskOarsService.deleteTaskOars(taskOars,taskOarsIds);
            return success();
        } catch (Exception ex) {
            return failure(ex,"删除失败");
        }
    }

    /**
    * 物理删除 TaskOars
    * @author ganjun
    * @date 2024-11-18 10:34:59
    */
    @Log("物理删除TaskOars")
    @GetMapping("taskOars/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("taskOars:delete")
    public FebsResponse physicallyDeleteTaskOars(@PathVariable("id") String taskOarsIds) throws FebsException {
        try {
            this.taskOarsService.physicallyDeleteTaskOars(taskOarsIds);
            return success();
        } catch (Exception ex) {
            return failure(ex,"删除失败");
        }
    }

    /**
     * 修改 TaskOars
     * @author ganjun
     * @date 2024-11-18 10:34:59
     */
    @Log("修改TaskOars")
    @PostMapping("taskOars/update")
    @ResponseBody
    @RequiresPermissions("taskOars:edit")
    public FebsResponse updateTaskOars(TaskOars taskOars) throws FebsException {
        try {
            this.taskOarsService.updateTaskOars(taskOars);
            return success();
        } catch (Exception ex) {
            return failure(ex,"修改失败");
        }
    }

}
